unit upasCashDrawer0101main;
{$I LogOption.txt}

interface
uses
  Classes,
  upasserversocashdrawer0101;

procedure initialize(Params: TStringList);
procedure finalize;

var
  CashDrawer: EOupasserversocashdrawer0101;

implementation
uses
  {$IFDEF LOGUNITTEST}
  AuditLog,
  {$ENDIF}
  ParamUtil,
  upasparam,
  INI_XCashDrawer;

{$IFDEF LOGUNITTEST}
const
  eventsource = 'upasCashDrawer0101main';
{$ENDIF}

procedure initialize(Params: TStringList);
var
  iniCashDrawer: EOIniXCashDrawer;
  sw_a: String;
begin
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, eventsource + '.initialize', 'Setup Cash Drawer');
  {$ENDIF}

  sw_a := ParamUtil.getSwitch(Params, upasparam.Switch_a);
  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, eventsource + '.initialize', 'sw_a="' + sw_a + '"');
  {$ENDIF}

  iniCashDrawer := EOIniXCashDrawer.Create(sw_a);
  try
    if iniCashDrawer.OPOSForecLDN then
      CashDrawer := EOupasserversocashdrawer0101.Create(iniCashDrawer.DeviceName, 1, iniCashDrawer.OPOSLDN)
    else
      CashDrawer := EOupasserversocashdrawer0101.Create(iniCashDrawer.DeviceName, 1);
  finally
    iniCashDrawer.Free;
  end;
end;

procedure finalize;
begin
  CashDrawer.Free;

  {$IFDEF LOGUNITTEST}
  AuditLog.EventLog(AuditLog.etDUNIT, eventsource + '.finalize', '');
  {$ENDIF}
end;

end.
